/**   
 * Copyright © 2016 北京之洲科技有限责任公司. All rights reserved.
 * 
 * @Title: NewsReflectFileOfAutoHome.java 
 * @Prject: carfactory
 * @Package: com.zizo.reflect.autohome.news 
 * @Description: 
 * @author: Alexis  
 * @email heyan0227@outlook.com
 * @date: 2016年8月10日 上午11:21:47 
 * @version: V1.0   
 */
package com.zizo.reflect.autohome.news;

import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import com.zizo.core.ReflectFile;
import com.zizo.util.Util;

/**
 * @ClassName: NewsReflectFileOfAutoHome
 * @Description:
 * @author: Alexis
 * @date: 2016年8月10日 上午11:21:47
 */
public class NewsPostReflectFileOfAutoHome extends ReflectFile {

	/**
	 * @Title:NewsReflectFileOfAutoHome
	 * @Description:
	 * @param id
	 */
	public NewsPostReflectFileOfAutoHome(String id) {
		super(id);
	}

	public void getItems() {
		String pathname = "D:/var/server/reflectfile/autohome/news/" + this.id + "/" + this.id + ".html";
		Document doc = Util.readFile(pathname);
		Elements contents = doc.select("div#auto-channel-lazyload-article ul.article li:not(#ad_tw_04)");
		for (Element content : contents) {
			Element span = content.select("span.fn-right em").first();
			String link = content.select("a").first().attr("href");
			String lls = span.text();// 浏览数
			int l = 0;
			if (lls.contains("万")) {
				l = (int) Double.parseDouble(lls.split("万")[0]) * 10000;
			} else {
				l = Integer.parseInt(lls);
			}
			String itemID = link.split("/")[5].split("\\.")[0];
			if (itemID.contains("-")) {
				itemID = itemID.split("-")[0];
			}
			Util.downloadWebsite("D:/var/server/reflectfile/autohome/news/" + this.id + "/" + itemID,
					"post_" + itemID + "_" + l + ".html", link);
		}
		System.out.println(this.id);
	}

	/*
	 * (non Javadoc)
	 * 
	 * @Title: run
	 * 
	 * @Description:
	 * 
	 * @see com.zizo.core.ReflectFile#run()
	 */
	@Override
	public void run() {
		getItems();
	}

	public static void main(String[] args) {
		NewsPostReflectFileOfAutoHome post = new NewsPostReflectFileOfAutoHome("1");
		post.run();
	}
}
